from core.base import ComponentMeta, Plugin
from core.std import Action
#from core.graph import Pipeline
from core import cmds

import api
from core.manager import PluginManager

'''
class NewInstance(Action):
    types = [ComponentMeta]
    
    def name(self, obj): return "Make New " + str(obj)
    
    def do(self, obj, **kw):
        obj()
'''

class NewNodeType(Action):
    types = [ni.Util, ni.Node]
    name = "Make new Node"
    
    @classmethod
    def has_action(self, obj):
        return obj is ni.Util
    
    def do(self, obj, **kw):
        PluginManager().new_component_plugin(obj)

class AddViewToMainWindow(Action):
    types = [ni.View]
    options = ["Left", "Right", "Top", "Bottom", "Center"]
    name = "Add to Layout"
    
    def do(self, obj, **kw):
        cmds.main_window().add_view(obj, kw.get('option'))
        
class RefreshView(Action):
    types = [ni.View]
    name = "Refresh"
    
    def do(self, obj, **kw):
        obj.update_widgets()
        
class RunPipeline(Action):
    types = [ni.Pipeline]
    name = "Run"
    
    def do(self, obj, **kw):
        obj.update()
        
class ReloadPlugin(Action):
    types = [Plugin]
    name = "Reload"
    
    def do(self, obj, **kw):
        PluginManager().load_plugin(obj)
        
        
class CommitPlugin(Action):
    types = [Plugin]
    name = "Commit"
    
    def do(self, obj, **kw):
        PluginManager().commit_plugin(obj)
    
    
class RevertToLatest(Action):
    types = [Plugin]
    name = "Get Latest"
    
    def do(self, obj, **kw):
        PluginManager().revert_to_latest(obj)
    
#class RevertRevision(Action):
#    types = [Revision]
#    name = "Revert"



    